package com.vdf.sisconsolid.persistencemodule.converter;

import com.vdf.sisconsolid.persistencemodule.dto.TracingDTO;
import com.vdf.sisconsolid.persistencemodule.model.Consolidation;
import com.vdf.sisconsolid.persistencemodule.model.Tracing;
import com.vdf.sisconsolid.persistencemodule.model.TracingType;

public class TracingConverter {

	public static TracingDTO toDTO(Tracing tracing) {
		TracingDTO tDTO = new TracingDTO();
		tDTO.setIdTracing(tracing.getId());
//		tDTO.setIdTracingType(tracing.getTracingType().getId());
//		tDTO.setTracingType(tracing.getTracingType().getName());
		tDTO.setAttendedCell(tracing.getAttendedCell());
		tDTO.setAttendedService(tracing.getAttendedService());
		tDTO.setDateAccomplished(tracing.getDateAccomplished());
		tDTO.setTimeAccomplished(tracing.getTimeAccomplished());
		if (tracing.getCell() != null) {
			tDTO.setIdCell(tracing.getCell().getId());
		}
		tDTO.setNeed(tracing.getNeed());
		tDTO.setResult(tracing.getResult());

		return tDTO;
	}

	public static Tracing toEntity(TracingDTO tDTO) {

		Tracing tracing = new Tracing();
		tracing.setId(tDTO.getIdTracing());
		tracing.setConsolidation(newConsolidation(tDTO.getIdConsolidation()));
		tracing.setTracingType(newTracingType(tDTO.getIdTracingType()));
		tracing.setAttendedCell(tDTO.getAttendedCell());
		tracing.setAttendedService(tDTO.getAttendedService());
		tracing.setDateAccomplished(tDTO.getDateAccomplished());
		tracing.setTimeAccomplished(tDTO.getTimeAccomplished());
		tracing.setResult(tDTO.getResult());
		tracing.setNeed(tDTO.getNeed());
		tracing.setIdCell(tDTO.getIdCell());

		return tracing;
	}
	
	private static Consolidation newConsolidation(Long id) {
		Consolidation consolidation = new Consolidation();
		consolidation.setId(id);
		return consolidation;
	}
	
	private static TracingType newTracingType(Long id) {
		TracingType tracingType = new TracingType();
		tracingType.setId(id);
		return tracingType;
	}

}
